//
//  QualityReportController.swift
//  QualityControlSystem
//
//  Created by dundun on 17/1/11.
//  Copyright © 2017年 com.mask. All rights reserved.
//

import UIKit

class QualityReportController: UITableViewController {
    
    var modelArr: [QualityReport]?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = Color.bgGray
        loadData()
    }
    
    func loadData() {
        modelArr = [QualityReport]()
        for i in 0...7 {
            let qualityReport = QualityReport()
            if i == 0 || i == 3 || i == 7 {
                qualityReport.isQualified = true
                qualityReport.checkTitle = "池体"
                qualityReport.checkContent = "池体大小、长宽高检查"
            } else {
                qualityReport.isQualified = false
                qualityReport.checkTitle = "下布水"
                qualityReport.checkContent = "下布水是否完成"
                qualityReport.checkReason = "工艺不符合要求"
            }
            modelArr?.append(qualityReport)
        }
        tableView.reloadData()
    }

    // MARK: - Table view data source
    
    override func numberOfSections(in tableView: UITableView) -> Int {
        return modelArr?.count ?? 0
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var qualityReportCell = tableView.dequeueReusableCell(withIdentifier: "qualityReportCell") as? QualityReportCell
        if qualityReportCell == nil {
            qualityReportCell = QualityReportCell.init(style: .default, reuseIdentifier: "qualityReportCell")
        }
        qualityReportCell?.model = modelArr?[indexPath.section]
        return qualityReportCell!
    }
    
    // MARK: - Table view delegate
    
    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let model = modelArr?[indexPath.section]
        if model?.isQualified == true {
            return 100
        } else {
            return 140
        }
    }
    
    override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 5
    }
    
    override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let historyPicListVC = ReviewPhotosController ()
        historyPicListVC.reviewType = ReviewType.reviewFailure
        historyPicListVC.workerType = WorkerType.other
        navigationController?.pushViewController(historyPicListVC, animated: true)
    }

}
